# This is a sample Python script.

# Press ⌃R to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.

import cv2 as cv
import numpy as np
import point


def resize_img(image, height=1800):
    h, w = image.shape[:2]
    pro = height / h
    s_w = int(w * pro)
    s_h = int(height)
    size = (s_w, s_h)
    img = cv.resize(image, size)
    return img, s_h, s_w, pro


# path = '/Users/wanggh/Desktop/a.jpeg'
path = '/Users/wanggh/Desktop/b.jpeg'
# path = '/Users/wanggh/Desktop/c.jpeg'
# path = '/Users/wanggh/Desktop/d.jpeg'
# path = '/Users/wanggh/Desktop/e.jpeg'
# path = '/Users/wanggh/Desktop/original.jpeg'

src = cv.imread(path)
src, src_h, src_w, src_pro = resize_img(src)
gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
# 高斯平滑
gray = cv.GaussianBlur(gray, (3, 3), sigmaX=5, sigmaY=5, borderType=cv.BORDER_DEFAULT)
# 边缘检测
# gray = cv.Canny(gray, 25, 50, apertureSize=3, L2gradient=False)
# 边缘检测
gray = cv.Canny(gray, 50, 150, apertureSize=3, L2gradient=True)
# 直线检测
lines = cv.HoughLinesP(gray, 1, np.pi / 180, 100, minLineLength=150, maxLineGap=100)
for line in lines:
    x1, y1, x2, y2 = line[0]
    if x1 <= 675 and x2 <= 675:
        print(line[0])
        cv.line(src, (x1, y1), (x2, y2), (0, 0, 255), 2)
cv.imshow("test", src)
cv.waitKey(0)
cv.destroyAllWindows()
